<template>
  <div class="todo-footer" v-if="todos.length > 0">
    <div class="stats">
      <span>总计: {{ todos.length }} 个</span>
      <span>待完成: {{ remainingTodos }} 个</span>
      <button 
        @click="$emit('clear-completed')" 
        class="clear-btn" 
        v-if="hasCompleted"
      >
        清除已完成
      </button>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  todos: {
    type: Array,
    default: () => []
  }
})

const remainingTodos = computed(() => {
  return props.todos.filter(t => !t.completed).length
})

const hasCompleted = computed(() => {
  return props.todos.some(t => t.completed)
})

defineEmits(['clear-completed'])
</script>

<style scoped>
.todo-footer {
  margin-top: 1rem;
}

.stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background-color: #f5f5f5;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #666;
}

.clear-btn {
  padding: 0.5rem 1rem;
  background-color: #ff9800;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

.clear-btn:hover {
  background-color: #e68900;
}
</style>